package net.gdface.cassdk;

import java.util.Collections;
import java.util.List;

/**
 * CASSDK版本定义
 * @author guyadong
 *
 */
public enum Version{
	/** 5.4.0 版本*/
	V5_4_0(
			"5.4.0",
			"libTHDetect_dpbin.so,libTHFacialPos_con.so,libTHFacialPos_lmp.so,libTHFeature_db10.so,libTHFeature_dis.so",
			"feadb.db10"),
	/** 8.0.0 版本*/
	V8_0_0(
			"8.0.0",
			"libTHDetect_dpbin.so,libTHFacialPos_con.so,libTHFacialPos_lmp.so,libTHFeature_db40.so",
			"feadb.db40");
	/** CASSDK版本号 */
	public  final String version;
	/** (Linux)需要复制到${user.dir}或JVM folder的模型文件列表(immutable) */
	private final List<String> linuxModelFiles;
	/** (Windows)需要复制到${user.dir}或JVM folder的模型文件列表(immutable) */
	private final List<String> windowsModelFiles;
	Version(String version,String linuxModelFiles,String windowsModelFiles){
		this(version,
				CasConfig.getExplodedStringAsList(linuxModelFiles),
				CasConfig.getExplodedStringAsList(windowsModelFiles));
	}
	Version(String version,Version v){
		this(version,v.linuxModelFiles,v.windowsModelFiles);
	}
	Version(String version,List<String> linuxModelFiles,List<String> windowsModelFiles){
		this.version= version;
		this.linuxModelFiles=null == linuxModelFiles 
				? Collections.<String>emptyList()
				: Collections.unmodifiableList(linuxModelFiles);
		this.windowsModelFiles = null == windowsModelFiles
				? Collections.<String>emptyList()
				: Collections.unmodifiableList(windowsModelFiles);
	}
	/**
	 * 根据CASSDK版本号返回匹配的{@link Version}
	 * @param version 版本号字符串
	 * @return
	 */
	public static final Version cast(String version){
		for(Version v : Version.values()){
			if(v.version.equals(version)){
				return v;
			}
		}
		throw new IllegalArgumentException(
	            "No enum constant " + Version.class.getCanonicalName() + "." + version);
	}
	/** 根据操作系统类型返回需要复制到${user.dir}或JVM folder的模型文件列表 */
	public List<String> getModelFiles(){
		return System.getProperty("os.name").toLowerCase().startsWith("win") 
					? windowsModelFiles
					: linuxModelFiles;
	}
	public List<String> getLinuxModelFiles() {
		return linuxModelFiles;
	}
	public List<String> getWindowsModelFiles() {
		return windowsModelFiles;
	}
}